package com.zjhcsoft.shop.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zjhcsoft.shop.dao.ProductDao;
import com.zjhcsoft.shop.model.ListProduct;
import com.zjhcsoft.shop.model.Product;
import com.zjhcsoft.shop.service.ProductService;
import com.zjhcsoft.util.CommonUtil;

@Service
public class ProductServiceImpl implements ProductService {
	@Resource
	private ProductDao productDao;
	//private static final Logger logger = Logger.getLogger(ProductrServiceImpl.class);
	
	/**
	 * 保存一件衣服产品对象
	 */
	public void  saveOrUpdate(Product  product){
		productDao.saveOrUpdate(product);
	}
	
	/**
	 * 根据ID获取产品对象
	 * @param id
	 * @return
	 */
	public Product load(Long id){
		return 	productDao.load(id);
	}
	
	/**
	 * 查找前50条
	 * @param kindid 产品归类，1:新品商品，2:精品推荐，3:特价商品
	 * @param size
	 * @param order
	 * @return
	 */
	public List<ListProduct> findProductList(Integer kindid, Integer size, String order){
		List<ListProduct> reslist=new ArrayList<ListProduct>();
		List<Product> list = productDao.findProductList(kindid, size, order);
		for(Product p:list){
			ListProduct lp=new ListProduct();
			lp.setId(p.getId());
			lp.setPic(CommonUtil.jsonStr2First(p.getBigpic()));
			lp.setSalePrice(p.getSalePrice());
			lp.setPurchasePrice(p.getPurchasePrice());
			lp.setWholesalePrice(p.getWholesalePrice());
			reslist.add(lp);
		}
		return reslist;
	}
}
